package es.udc.fic.hamNeggs.pojo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import java.sql.Date;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "hamneggs.userstories")
public class UserStories {

    @Id
    @GeneratedValue
    @Column(name = "ust_id")
    private Long                    id;

    @Column(name = "ust_name")
    private String                  name;

    @Column(name = "ust_description")
    private String                  description;

    @Column(name = "ust_realstorypoints")
    private Integer                 realstoryPoints;

    @Column(name = "ust_estimatedstoryPoints")
    private Integer                 estimatedstoryPoints;

    @Column(name = "ust_creationDate")
    private Date                    creationDate;

    @Column(name = "ust_state")
    @Enumerated(EnumType.STRING)
    private State                   state;

    @ManyToOne
    @JoinColumn(name = "prj_id")
    private Project                 project;

    @ManyToOne
    @JoinColumn(name = "spr_id")
    private Sprint                  sprint;

    @ManyToOne
    @JoinColumn(name = "usr_id")
    private User                    user;

    @OneToMany(mappedBy = "userStories")
    private Set<UserStoriesComment> comments;

    @ManyToOne
    @JoinColumn(name = "ctg_id")
    private UserStoriesCategory     userStoriesCategory;

    public UserStories() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getRealstoryPoints() {
        if (realstoryPoints == null)
            return 0;
        return realstoryPoints;
    }

    public void setRealstoryPoints(Integer realstoryPoints) {
        this.realstoryPoints = realstoryPoints;
    }

    public Integer getEstimatedstoryPoints() {
        if (estimatedstoryPoints == null)
            return 0;
        return estimatedstoryPoints;
    }

    public void setEstimatedstoryPoints(Integer estimatedstoryPoints) {
        this.estimatedstoryPoints = estimatedstoryPoints;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Long getId() {
        return id;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project myProject) {
        this.project = myProject;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public Sprint getSprint() {
        return sprint;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Set<UserStoriesComment> getComments() {
        return comments;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setOneComment(UserStoriesComment cmt) {
        if (comments == null)
            comments = new HashSet<UserStoriesComment>();
        comments.add(cmt);
    }

    public void setSprint(Sprint sprint) {
        this.sprint = sprint;
    }

    public void setComments(Set<UserStoriesComment> comments) {
        this.comments = comments;
    }

    public UserStoriesCategory getUserStoriesCategory() {
        return userStoriesCategory;
    }

    public void setUserStoriesCategory(UserStoriesCategory userStoriesCategory) {
        this.userStoriesCategory = userStoriesCategory;
    }

    public enum State {
        Created("Created"),
        InProgress("InProgress"),
        Finalized("Finalized"),
        Validated("Validated");

        private final String state;

        private State(final String state) {
            this.state = state;
        }

        public String getString() {
            return state;
        }
    }

}
